package com.catchu.pattern.creational.迭代器模式.d双向迭代器.iterator;

import com.catchu.pattern.creational.迭代器模式.d双向迭代器.aggregate.ListPayAggregate;

public class ListPayIterator implements Iterator{

    /**
     * 持有聚合对象
     */
    private ListPayAggregate listPayAggregate;

    public ListPayIterator(ListPayAggregate listPayAggregate) {
        this.listPayAggregate = listPayAggregate;
    }

    /**
     * 索引下标，默认是-1
     */
    private Integer index = -1;

    @Override
    public void first() {
        this.index = 0;
    }

    @Override
    public void next() {
        if(index<listPayAggregate.size()){
            index++;
        }
    }

    @Override
    public boolean isDone() {
        if(index==listPayAggregate.size()){
            return true;
        }
        return false;
    }

    @Override
    public Object currentItem() {
        return listPayAggregate.get(index);
    }

    @Override
    public boolean isFirst() {
        return this.index==0;
    }

    @Override
    public void previous() {
        if(index>0){
            index--;
        }
    }
}
